<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of product
 *
 * @author sonUIT
 */
class product extends CI_Controller {

    public function __construct() {
        parent::__construct();
    }

    /* load all product */

    public function index() {
        
    }

    /* load products of catalog */

    public function catalog($id) {
        $this->load->model('mproduct');
        $data = array();
        $pro = new Mproduct();
        $data['bang'] = $pro->GetAllProducts();
        $this->load->view('header_view');
        $this->load->view('top-level1_view');
        $this->load->view('slideshow_view');
        $this->load->view('main_start_view');
        $this->load->view('allproduct_view');
        $this->load->view('main_end_view');
        $this->load->view('footer_view');
    }

    public function Detail() {
        if (isset($_GET['matp'])) {
            $matp = $_GET['matp'];
            $data = array();
            $this->load->model("mproduct");
            $sach = new Mproduct();
            $sach->Get($matp);

// var_dump( $sach->Get($matp));
            if ($sach->Get($matp)) {
                $data['sach'] = $sach;
                $this->load->model("mtacgia");
                $tacgia = new Mtacgia();
                $tacgia->GetByMatg($sach->matg);
                $data['tacgia'] = $tacgia;
                $this->load->model("mnhaxuatban");
                $nxb = new Mnhaxuatban();
                $nxb->GetByManxb($sach->manxb);
                $data['nxb'] = $nxb;
                $data['title'] = "Chi tiết sản phẩm";
                $this->load->view('header_view', $data);
                $this->load->view('top-level1_view');
                $this->load->view('main_start_view');
                $this->load->view("product_detail_view");
//$this->load->view('allproduct_view');
                $this->load->view('main_end_view');
                $this->load->view('footer_view');
            }
        }
        else
            echo"trang k ton tai";
    }

    public function GetAll() {
        $this->load->model('mproduct');
        $mproducts = new Mproduct();
        $data = array();
        $data['products'] = $mproducts->GetAllProducts();
      //  $data['tacgias'] = array();
        $this->load->model("mtacgia");
        $tacgia = new Mtacgia();
        $data['tacgias']=array(array());
        foreach ($data['products'] as $row) {
            $tacgia->GetByMatg($row["MATG"]);
            
            array_push($data['tacgias'],$tacgia );
        }
       // var_dump($data['tacgias']);
        $this->load->view('products_view', $data);
    }

}

?>
